// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Fluent;
using Elastic.Clients.Elasticsearch.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.MachineLearning;

public sealed partial class AnalysisConfig
{
	/// <summary>
	/// <para>
	/// The size of the interval that the analysis is aggregated into, typically between <c>5m</c> and <c>1h</c>. This value should be either a whole number of days or equate to a
	/// whole number of buckets in one day. If the anomaly detection job uses a datafeed with aggregations, this value must also be divisible by the interval of the date histogram aggregation.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("bucket_span")]
	public Elastic.Clients.Elasticsearch.Duration? BucketSpan { get; set; }

	/// <summary>
	/// <para>
	/// If <c>categorization_field_name</c> is specified, you can also define the analyzer that is used to interpret the categorization field. This property cannot be used at the same time as <c>categorization_filters</c>. The categorization analyzer specifies how the <c>categorization_field</c> is interpreted by the categorization process. The <c>categorization_analyzer</c> field can be specified either as a string or as an object. If it is a string, it must refer to a built-in analyzer or one added by another plugin.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("categorization_analyzer")]
	public Elastic.Clients.Elasticsearch.MachineLearning.CategorizationAnalyzer? CategorizationAnalyzer { get; set; }

	/// <summary>
	/// <para>
	/// If this property is specified, the values of the specified field will be categorized. The resulting categories must be used in a detector by setting <c>by_field_name</c>, <c>over_field_name</c>, or <c>partition_field_name</c> to the keyword <c>mlcategory</c>.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("categorization_field_name")]
	public Elastic.Clients.Elasticsearch.Field? CategorizationFieldName { get; set; }

	/// <summary>
	/// <para>
	/// If <c>categorization_field_name</c> is specified, you can also define optional filters. This property expects an array of regular expressions. The expressions are used to filter out matching sequences from the categorization field values. You can use this functionality to fine tune the categorization by excluding sequences from consideration when categories are defined. For example, you can exclude SQL statements that appear in your log files. This property cannot be used at the same time as <c>categorization_analyzer</c>. If you only want to define simple regular expression filters that are applied prior to tokenization, setting this property is the easiest method. If you also want to customize the tokenizer or post-tokenization filtering, use the <c>categorization_analyzer</c> property instead and include the filters as pattern_replace character filters. The effect is exactly the same.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("categorization_filters")]
	public ICollection<string>? CategorizationFilters { get; set; }

	/// <summary>
	/// <para>
	/// Detector configuration objects specify which data fields a job analyzes. They also specify which analytical functions are used. You can specify multiple detectors for a job. If the detectors array does not contain at least one detector, no analysis can occur and an error is returned.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("detectors")]
	public ICollection<Elastic.Clients.Elasticsearch.MachineLearning.Detector> Detectors { get; set; }

	/// <summary>
	/// <para>
	/// A comma separated list of influencer field names. Typically these can be the by, over, or partition fields that are used in the detector configuration. You might also want to use a field name that is not specifically named in a detector, but is available as part of the input data. When you use multiple detectors, the use of influencers is recommended as it aggregates results for each influencer entity.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("influencers")]
	[JsonConverter(typeof(FieldsConverter))]
	public Elastic.Clients.Elasticsearch.Fields? Influencers { get; set; }

	/// <summary>
	/// <para>
	/// The size of the window in which to expect data that is out of time order. If you specify a non-zero value, it must be greater than or equal to one second. NOTE: Latency is applicable only when you send data by using the post data API.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("latency")]
	public Elastic.Clients.Elasticsearch.Duration? Latency { get; set; }

	/// <summary>
	/// <para>
	/// Advanced configuration option. Affects the pruning of models that have not been updated for the given time duration. The value must be set to a multiple of the <c>bucket_span</c>. If set too low, important information may be removed from the model. For jobs created in 8.1 and later, the default value is the greater of <c>30d</c> or 20 times <c>bucket_span</c>.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("model_prune_window")]
	public Elastic.Clients.Elasticsearch.Duration? ModelPruneWindow { get; set; }

	/// <summary>
	/// <para>
	/// This functionality is reserved for internal use. It is not supported for use in customer environments and is not subject to the support SLA of official GA features. If set to <c>true</c>, the analysis will automatically find correlations between metrics for a given by field value and report anomalies when those correlations cease to hold. For example, suppose CPU and memory usage on host A is usually highly correlated with the same metrics on host B. Perhaps this correlation occurs because they are running a load-balanced application. If you enable this property, anomalies will be reported when, for example, CPU usage on host A is high and the value of CPU usage on host B is low. That is to say, you’ll see an anomaly when the CPU of host A is unusual given the CPU of host B. To use the <c>multivariate_by_fields</c> property, you must also specify <c>by_field_name</c> in your detector.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("multivariate_by_fields")]
	public bool? MultivariateByFields { get; set; }

	/// <summary>
	/// <para>
	/// Settings related to how categorization interacts with partition fields.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("per_partition_categorization")]
	public Elastic.Clients.Elasticsearch.MachineLearning.PerPartitionCategorization? PerPartitionCategorization { get; set; }

	/// <summary>
	/// <para>
	/// If this property is specified, the data that is fed to the job is expected to be pre-summarized. This property value is the name of the field that contains the count of raw data points that have been summarized. The same <c>summary_count_field_name</c> applies to all detectors in the job. NOTE: The <c>summary_count_field_name</c> property cannot be used with the <c>metric</c> function.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("summary_count_field_name")]
	public Elastic.Clients.Elasticsearch.Field? SummaryCountFieldName { get; set; }
}

public sealed partial class AnalysisConfigDescriptor<TDocument> : SerializableDescriptor<AnalysisConfigDescriptor<TDocument>>
{
	internal AnalysisConfigDescriptor(Action<AnalysisConfigDescriptor<TDocument>> configure) => configure.Invoke(this);

	public AnalysisConfigDescriptor() : base()
	{
	}

	private Elastic.Clients.Elasticsearch.Duration? BucketSpanValue { get; set; }
	private Elastic.Clients.Elasticsearch.MachineLearning.CategorizationAnalyzer? CategorizationAnalyzerValue { get; set; }
	private Elastic.Clients.Elasticsearch.Field? CategorizationFieldNameValue { get; set; }
	private ICollection<string>? CategorizationFiltersValue { get; set; }
	private ICollection<Elastic.Clients.Elasticsearch.MachineLearning.Detector> DetectorsValue { get; set; }
	private Elastic.Clients.Elasticsearch.MachineLearning.DetectorDescriptor<TDocument> DetectorsDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.MachineLearning.DetectorDescriptor<TDocument>> DetectorsDescriptorAction { get; set; }
	private Action<Elastic.Clients.Elasticsearch.MachineLearning.DetectorDescriptor<TDocument>>[] DetectorsDescriptorActions { get; set; }
	private Elastic.Clients.Elasticsearch.Fields? InfluencersValue { get; set; }
	private Elastic.Clients.Elasticsearch.Duration? LatencyValue { get; set; }
	private Elastic.Clients.Elasticsearch.Duration? ModelPruneWindowValue { get; set; }
	private bool? MultivariateByFieldsValue { get; set; }
	private Elastic.Clients.Elasticsearch.MachineLearning.PerPartitionCategorization? PerPartitionCategorizationValue { get; set; }
	private Elastic.Clients.Elasticsearch.MachineLearning.PerPartitionCategorizationDescriptor PerPartitionCategorizationDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.MachineLearning.PerPartitionCategorizationDescriptor> PerPartitionCategorizationDescriptorAction { get; set; }
	private Elastic.Clients.Elasticsearch.Field? SummaryCountFieldNameValue { get; set; }

	/// <summary>
	/// <para>
	/// The size of the interval that the analysis is aggregated into, typically between <c>5m</c> and <c>1h</c>. This value should be either a whole number of days or equate to a
	/// whole number of buckets in one day. If the anomaly detection job uses a datafeed with aggregations, this value must also be divisible by the interval of the date histogram aggregation.
	/// </para>
	/// </summary>
	public AnalysisConfigDescriptor<TDocument> BucketSpan(Elastic.Clients.Elasticsearch.Duration? bucketSpan)
	{
		BucketSpanValue = bucketSpan;
		return Self;
	}

	/// <summary>
	/// <para>
	/// If <c>categorization_field_name</c> is specified, you can also define the analyzer that is used to interpret the categorization field. This property cannot be used at the same time as <c>categorization_filters</c>. The categorization analyzer specifies how the <c>categorization_field</c> is interpreted by the categorization process. The <c>categorization_analyzer</c> field can be specified either as a string or as an object. If it is a string, it must refer to a built-in analyzer or one added by another plugin.
	/// </para>
	/// </summary>
	public AnalysisConfigDescriptor<TDocument> CategorizationAnalyzer(Elastic.Clients.Elasticsearch.MachineLearning.CategorizationAnalyzer? categorizationAnalyzer)
	{
		CategorizationAnalyzerValue = categorizationAnalyzer;
		return Self;
	}

	/// <summary>
	/// <para>
	/// If this property is specified, the values of the specified field will be categorized. The resulting categories must be used in a detector by setting <c>by_field_name</c>, <c>over_field_name</c>, or <c>partition_field_name</c> to the keyword <c>mlcategory</c>.
	/// </para>
	/// </summary>
	public AnalysisConfigDescriptor<TDocument> CategorizationFieldName(Elastic.Clients.Elasticsearch.Field? categorizationFieldName)
	{
		CategorizationFieldNameValue = categorizationFieldName;
		return Self;
	}

	/// <summary>
	/// <para>
	/// If this property is specified, the values of the specified field will be categorized. The resulting categories must be used in a detector by setting <c>by_field_name</c>, <c>over_field_name</c>, or <c>partition_field_name</c> to the keyword <c>mlcategory</c>.
	/// </para>
	/// </summary>
	public AnalysisConfigDescriptor<TDocument> CategorizationFieldName<TValue>(Expression<Func<TDocument, TValue>> categorizationFieldName)
	{
		CategorizationFieldNameValue = categorizationFieldName;
		return Self;
	}

	/// <summary>
	/// <para>
	/// If this property is specified, the values of the specified field will be categorized. The resulting categories must be used in a detector by setting <c>by_field_name</c>, <c>over_field_name</c>, or <c>partition_field_name</c> to the keyword <c>mlcategory</c>.
	/// </para>
	/// </summary>
	public AnalysisConfigDescriptor<TDocument> CategorizationFieldName(Expression<Func<TDocument, object>> categorizationFieldName)
	{
		CategorizationFieldNameValue = categorizationFieldName;
		return Self;
	}

	/// <summary>
	/// <para>
	/// If <c>categorization_field_name</c> is specified, you can also define optional filters. This property expects an array of regular expressions. The expressions are used to filter out matching sequences from the categorization field values. You can use this functionality to fine tune the categorization by excluding sequences from consideration when categories are defined. For example, you can exclude SQL statements that appear in your log files. This property cannot be used at the same time as <c>categorization_analyzer</c>. If you only want to define simple regular expression filters that are applied prior to tokenization, setting this property is the easiest method. If you also want to customize the tokenizer or post-tokenization filtering, use the <c>categorization_analyzer</c> property instead and include the filters as pattern_replace character filters. The effect is exactly the same.
	/// </para>
	/// </summary>
	public AnalysisConfigDescriptor<TDocument> CategorizationFilters(ICollection<string>? categorizationFilters)
	{
		CategorizationFiltersValue = categorizationFilters;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Detector configuration objects specify which data fields a job analyzes. They also specify which analytical functions are used. You can specify multiple detectors for a job. If the detectors array does not contain at least one detector, no analysis can occur and an error is returned.
	/// </para>
	/// </summary>
	public AnalysisConfigDescriptor<TDocument> Detectors(ICollection<Elastic.Clients.Elasticsearch.MachineLearning.Detector> detectors)
	{
		DetectorsDescriptor = null;
		DetectorsDescriptorAction = null;
		DetectorsDescriptorActions = null;
		DetectorsValue = detectors;
		return Self;
	}

	public AnalysisConfigDescriptor<TDocument> Detectors(Elastic.Clients.Elasticsearch.MachineLearning.DetectorDescriptor<TDocument> descriptor)
	{
		DetectorsValue = null;
		DetectorsDescriptorAction = null;
		DetectorsDescriptorActions = null;
		DetectorsDescriptor = descriptor;
		return Self;
	}

	public AnalysisConfigDescriptor<TDocument> Detectors(Action<Elastic.Clients.Elasticsearch.MachineLearning.DetectorDescriptor<TDocument>> configure)
	{
		DetectorsValue = null;
		DetectorsDescriptor = null;
		DetectorsDescriptorActions = null;
		DetectorsDescriptorAction = configure;
		return Self;
	}

	public AnalysisConfigDescriptor<TDocument> Detectors(params Action<Elastic.Clients.Elasticsearch.MachineLearning.DetectorDescriptor<TDocument>>[] configure)
	{
		DetectorsValue = null;
		DetectorsDescriptor = null;
		DetectorsDescriptorAction = null;
		DetectorsDescriptorActions = configure;
		return Self;
	}

	/// <summary>
	/// <para>
	/// A comma separated list of influencer field names. Typically these can be the by, over, or partition fields that are used in the detector configuration. You might also want to use a field name that is not specifically named in a detector, but is available as part of the input data. When you use multiple detectors, the use of influencers is recommended as it aggregates results for each influencer entity.
	/// </para>
	/// </summary>
	public AnalysisConfigDescriptor<TDocument> Influencers(Elastic.Clients.Elasticsearch.Fields? influencers)
	{
		InfluencersValue = influencers;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The size of the window in which to expect data that is out of time order. If you specify a non-zero value, it must be greater than or equal to one second. NOTE: Latency is applicable only when you send data by using the post data API.
	/// </para>
	/// </summary>
	public AnalysisConfigDescriptor<TDocument> Latency(Elastic.Clients.Elasticsearch.Duration? latency)
	{
		LatencyValue = latency;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Advanced configuration option. Affects the pruning of models that have not been updated for the given time duration. The value must be set to a multiple of the <c>bucket_span</c>. If set too low, important information may be removed from the model. For jobs created in 8.1 and later, the default value is the greater of <c>30d</c> or 20 times <c>bucket_span</c>.
	/// </para>
	/// </summary>
	public AnalysisConfigDescriptor<TDocument> ModelPruneWindow(Elastic.Clients.Elasticsearch.Duration? modelPruneWindow)
	{
		ModelPruneWindowValue = modelPruneWindow;
		return Self;
	}

	/// <summary>
	/// <para>
	/// This functionality is reserved for internal use. It is not supported for use in customer environments and is not subject to the support SLA of official GA features. If set to <c>true</c>, the analysis will automatically find correlations between metrics for a given by field value and report anomalies when those correlations cease to hold. For example, suppose CPU and memory usage on host A is usually highly correlated with the same metrics on host B. Perhaps this correlation occurs because they are running a load-balanced application. If you enable this property, anomalies will be reported when, for example, CPU usage on host A is high and the value of CPU usage on host B is low. That is to say, you’ll see an anomaly when the CPU of host A is unusual given the CPU of host B. To use the <c>multivariate_by_fields</c> property, you must also specify <c>by_field_name</c> in your detector.
	/// </para>
	/// </summary>
	public AnalysisConfigDescriptor<TDocument> MultivariateByFields(bool? multivariateByFields = true)
	{
		MultivariateByFieldsValue = multivariateByFields;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Settings related to how categorization interacts with partition fields.
	/// </para>
	/// </summary>
	public AnalysisConfigDescriptor<TDocument> PerPartitionCategorization(Elastic.Clients.Elasticsearch.MachineLearning.PerPartitionCategorization? perPartitionCategorization)
	{
		PerPartitionCategorizationDescriptor = null;
		PerPartitionCategorizationDescriptorAction = null;
		PerPartitionCategorizationValue = perPartitionCategorization;
		return Self;
	}

	public AnalysisConfigDescriptor<TDocument> PerPartitionCategorization(Elastic.Clients.Elasticsearch.MachineLearning.PerPartitionCategorizationDescriptor descriptor)
	{
		PerPartitionCategorizationValue = null;
		PerPartitionCategorizationDescriptorAction = null;
		PerPartitionCategorizationDescriptor = descriptor;
		return Self;
	}

	public AnalysisConfigDescriptor<TDocument> PerPartitionCategorization(Action<Elastic.Clients.Elasticsearch.MachineLearning.PerPartitionCategorizationDescriptor> configure)
	{
		PerPartitionCategorizationValue = null;
		PerPartitionCategorizationDescriptor = null;
		PerPartitionCategorizationDescriptorAction = configure;
		return Self;
	}

	/// <summary>
	/// <para>
	/// If this property is specified, the data that is fed to the job is expected to be pre-summarized. This property value is the name of the field that contains the count of raw data points that have been summarized. The same <c>summary_count_field_name</c> applies to all detectors in the job. NOTE: The <c>summary_count_field_name</c> property cannot be used with the <c>metric</c> function.
	/// </para>
	/// </summary>
	public AnalysisConfigDescriptor<TDocument> SummaryCountFieldName(Elastic.Clients.Elasticsearch.Field? summaryCountFieldName)
	{
		SummaryCountFieldNameValue = summaryCountFieldName;
		return Self;
	}

	/// <summary>
	/// <para>
	/// If this property is specified, the data that is fed to the job is expected to be pre-summarized. This property value is the name of the field that contains the count of raw data points that have been summarized. The same <c>summary_count_field_name</c> applies to all detectors in the job. NOTE: The <c>summary_count_field_name</c> property cannot be used with the <c>metric</c> function.
	/// </para>
	/// </summary>
	public AnalysisConfigDescriptor<TDocument> SummaryCountFieldName<TValue>(Expression<Func<TDocument, TValue>> summaryCountFieldName)
	{
		SummaryCountFieldNameValue = summaryCountFieldName;
		return Self;
	}

	/// <summary>
	/// <para>
	/// If this property is specified, the data that is fed to the job is expected to be pre-summarized. This property value is the name of the field that contains the count of raw data points that have been summarized. The same <c>summary_count_field_name</c> applies to all detectors in the job. NOTE: The <c>summary_count_field_name</c> property cannot be used with the <c>metric</c> function.
	/// </para>
	/// </summary>
	public AnalysisConfigDescriptor<TDocument> SummaryCountFieldName(Expression<Func<TDocument, object>> summaryCountFieldName)
	{
		SummaryCountFieldNameValue = summaryCountFieldName;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (BucketSpanValue is not null)
		{
			writer.WritePropertyName("bucket_span");
			JsonSerializer.Serialize(writer, BucketSpanValue, options);
		}

		if (CategorizationAnalyzerValue is not null)
		{
			writer.WritePropertyName("categorization_analyzer");
			JsonSerializer.Serialize(writer, CategorizationAnalyzerValue, options);
		}

		if (CategorizationFieldNameValue is not null)
		{
			writer.WritePropertyName("categorization_field_name");
			JsonSerializer.Serialize(writer, CategorizationFieldNameValue, options);
		}

		if (CategorizationFiltersValue is not null)
		{
			writer.WritePropertyName("categorization_filters");
			JsonSerializer.Serialize(writer, CategorizationFiltersValue, options);
		}

		if (DetectorsDescriptor is not null)
		{
			writer.WritePropertyName("detectors");
			writer.WriteStartArray();
			JsonSerializer.Serialize(writer, DetectorsDescriptor, options);
			writer.WriteEndArray();
		}
		else if (DetectorsDescriptorAction is not null)
		{
			writer.WritePropertyName("detectors");
			writer.WriteStartArray();
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.MachineLearning.DetectorDescriptor<TDocument>(DetectorsDescriptorAction), options);
			writer.WriteEndArray();
		}
		else if (DetectorsDescriptorActions is not null)
		{
			writer.WritePropertyName("detectors");
			writer.WriteStartArray();
			foreach (var action in DetectorsDescriptorActions)
			{
				JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.MachineLearning.DetectorDescriptor<TDocument>(action), options);
			}

			writer.WriteEndArray();
		}
		else
		{
			writer.WritePropertyName("detectors");
			JsonSerializer.Serialize(writer, DetectorsValue, options);
		}

		if (InfluencersValue is not null)
		{
			writer.WritePropertyName("influencers");
			JsonSerializer.Serialize(writer, InfluencersValue, options);
		}

		if (LatencyValue is not null)
		{
			writer.WritePropertyName("latency");
			JsonSerializer.Serialize(writer, LatencyValue, options);
		}

		if (ModelPruneWindowValue is not null)
		{
			writer.WritePropertyName("model_prune_window");
			JsonSerializer.Serialize(writer, ModelPruneWindowValue, options);
		}

		if (MultivariateByFieldsValue.HasValue)
		{
			writer.WritePropertyName("multivariate_by_fields");
			writer.WriteBooleanValue(MultivariateByFieldsValue.Value);
		}

		if (PerPartitionCategorizationDescriptor is not null)
		{
			writer.WritePropertyName("per_partition_categorization");
			JsonSerializer.Serialize(writer, PerPartitionCategorizationDescriptor, options);
		}
		else if (PerPartitionCategorizationDescriptorAction is not null)
		{
			writer.WritePropertyName("per_partition_categorization");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.MachineLearning.PerPartitionCategorizationDescriptor(PerPartitionCategorizationDescriptorAction), options);
		}
		else if (PerPartitionCategorizationValue is not null)
		{
			writer.WritePropertyName("per_partition_categorization");
			JsonSerializer.Serialize(writer, PerPartitionCategorizationValue, options);
		}

		if (SummaryCountFieldNameValue is not null)
		{
			writer.WritePropertyName("summary_count_field_name");
			JsonSerializer.Serialize(writer, SummaryCountFieldNameValue, options);
		}

		writer.WriteEndObject();
	}
}

public sealed partial class AnalysisConfigDescriptor : SerializableDescriptor<AnalysisConfigDescriptor>
{
	internal AnalysisConfigDescriptor(Action<AnalysisConfigDescriptor> configure) => configure.Invoke(this);

	public AnalysisConfigDescriptor() : base()
	{
	}

	private Elastic.Clients.Elasticsearch.Duration? BucketSpanValue { get; set; }
	private Elastic.Clients.Elasticsearch.MachineLearning.CategorizationAnalyzer? CategorizationAnalyzerValue { get; set; }
	private Elastic.Clients.Elasticsearch.Field? CategorizationFieldNameValue { get; set; }
	private ICollection<string>? CategorizationFiltersValue { get; set; }
	private ICollection<Elastic.Clients.Elasticsearch.MachineLearning.Detector> DetectorsValue { get; set; }
	private Elastic.Clients.Elasticsearch.MachineLearning.DetectorDescriptor DetectorsDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.MachineLearning.DetectorDescriptor> DetectorsDescriptorAction { get; set; }
	private Action<Elastic.Clients.Elasticsearch.MachineLearning.DetectorDescriptor>[] DetectorsDescriptorActions { get; set; }
	private Elastic.Clients.Elasticsearch.Fields? InfluencersValue { get; set; }
	private Elastic.Clients.Elasticsearch.Duration? LatencyValue { get; set; }
	private Elastic.Clients.Elasticsearch.Duration? ModelPruneWindowValue { get; set; }
	private bool? MultivariateByFieldsValue { get; set; }
	private Elastic.Clients.Elasticsearch.MachineLearning.PerPartitionCategorization? PerPartitionCategorizationValue { get; set; }
	private Elastic.Clients.Elasticsearch.MachineLearning.PerPartitionCategorizationDescriptor PerPartitionCategorizationDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.MachineLearning.PerPartitionCategorizationDescriptor> PerPartitionCategorizationDescriptorAction { get; set; }
	private Elastic.Clients.Elasticsearch.Field? SummaryCountFieldNameValue { get; set; }

	/// <summary>
	/// <para>
	/// The size of the interval that the analysis is aggregated into, typically between <c>5m</c> and <c>1h</c>. This value should be either a whole number of days or equate to a
	/// whole number of buckets in one day. If the anomaly detection job uses a datafeed with aggregations, this value must also be divisible by the interval of the date histogram aggregation.
	/// </para>
	/// </summary>
	public AnalysisConfigDescriptor BucketSpan(Elastic.Clients.Elasticsearch.Duration? bucketSpan)
	{
		BucketSpanValue = bucketSpan;
		return Self;
	}

	/// <summary>
	/// <para>
	/// If <c>categorization_field_name</c> is specified, you can also define the analyzer that is used to interpret the categorization field. This property cannot be used at the same time as <c>categorization_filters</c>. The categorization analyzer specifies how the <c>categorization_field</c> is interpreted by the categorization process. The <c>categorization_analyzer</c> field can be specified either as a string or as an object. If it is a string, it must refer to a built-in analyzer or one added by another plugin.
	/// </para>
	/// </summary>
	public AnalysisConfigDescriptor CategorizationAnalyzer(Elastic.Clients.Elasticsearch.MachineLearning.CategorizationAnalyzer? categorizationAnalyzer)
	{
		CategorizationAnalyzerValue = categorizationAnalyzer;
		return Self;
	}

	/// <summary>
	/// <para>
	/// If this property is specified, the values of the specified field will be categorized. The resulting categories must be used in a detector by setting <c>by_field_name</c>, <c>over_field_name</c>, or <c>partition_field_name</c> to the keyword <c>mlcategory</c>.
	/// </para>
	/// </summary>
	public AnalysisConfigDescriptor CategorizationFieldName(Elastic.Clients.Elasticsearch.Field? categorizationFieldName)
	{
		CategorizationFieldNameValue = categorizationFieldName;
		return Self;
	}

	/// <summary>
	/// <para>
	/// If this property is specified, the values of the specified field will be categorized. The resulting categories must be used in a detector by setting <c>by_field_name</c>, <c>over_field_name</c>, or <c>partition_field_name</c> to the keyword <c>mlcategory</c>.
	/// </para>
	/// </summary>
	public AnalysisConfigDescriptor CategorizationFieldName<TDocument, TValue>(Expression<Func<TDocument, TValue>> categorizationFieldName)
	{
		CategorizationFieldNameValue = categorizationFieldName;
		return Self;
	}

	/// <summary>
	/// <para>
	/// If this property is specified, the values of the specified field will be categorized. The resulting categories must be used in a detector by setting <c>by_field_name</c>, <c>over_field_name</c>, or <c>partition_field_name</c> to the keyword <c>mlcategory</c>.
	/// </para>
	/// </summary>
	public AnalysisConfigDescriptor CategorizationFieldName<TDocument>(Expression<Func<TDocument, object>> categorizationFieldName)
	{
		CategorizationFieldNameValue = categorizationFieldName;
		return Self;
	}

	/// <summary>
	/// <para>
	/// If <c>categorization_field_name</c> is specified, you can also define optional filters. This property expects an array of regular expressions. The expressions are used to filter out matching sequences from the categorization field values. You can use this functionality to fine tune the categorization by excluding sequences from consideration when categories are defined. For example, you can exclude SQL statements that appear in your log files. This property cannot be used at the same time as <c>categorization_analyzer</c>. If you only want to define simple regular expression filters that are applied prior to tokenization, setting this property is the easiest method. If you also want to customize the tokenizer or post-tokenization filtering, use the <c>categorization_analyzer</c> property instead and include the filters as pattern_replace character filters. The effect is exactly the same.
	/// </para>
	/// </summary>
	public AnalysisConfigDescriptor CategorizationFilters(ICollection<string>? categorizationFilters)
	{
		CategorizationFiltersValue = categorizationFilters;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Detector configuration objects specify which data fields a job analyzes. They also specify which analytical functions are used. You can specify multiple detectors for a job. If the detectors array does not contain at least one detector, no analysis can occur and an error is returned.
	/// </para>
	/// </summary>
	public AnalysisConfigDescriptor Detectors(ICollection<Elastic.Clients.Elasticsearch.MachineLearning.Detector> detectors)
	{
		DetectorsDescriptor = null;
		DetectorsDescriptorAction = null;
		DetectorsDescriptorActions = null;
		DetectorsValue = detectors;
		return Self;
	}

	public AnalysisConfigDescriptor Detectors(Elastic.Clients.Elasticsearch.MachineLearning.DetectorDescriptor descriptor)
	{
		DetectorsValue = null;
		DetectorsDescriptorAction = null;
		DetectorsDescriptorActions = null;
		DetectorsDescriptor = descriptor;
		return Self;
	}

	public AnalysisConfigDescriptor Detectors(Action<Elastic.Clients.Elasticsearch.MachineLearning.DetectorDescriptor> configure)
	{
		DetectorsValue = null;
		DetectorsDescriptor = null;
		DetectorsDescriptorActions = null;
		DetectorsDescriptorAction = configure;
		return Self;
	}

	public AnalysisConfigDescriptor Detectors(params Action<Elastic.Clients.Elasticsearch.MachineLearning.DetectorDescriptor>[] configure)
	{
		DetectorsValue = null;
		DetectorsDescriptor = null;
		DetectorsDescriptorAction = null;
		DetectorsDescriptorActions = configure;
		return Self;
	}

	/// <summary>
	/// <para>
	/// A comma separated list of influencer field names. Typically these can be the by, over, or partition fields that are used in the detector configuration. You might also want to use a field name that is not specifically named in a detector, but is available as part of the input data. When you use multiple detectors, the use of influencers is recommended as it aggregates results for each influencer entity.
	/// </para>
	/// </summary>
	public AnalysisConfigDescriptor Influencers(Elastic.Clients.Elasticsearch.Fields? influencers)
	{
		InfluencersValue = influencers;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The size of the window in which to expect data that is out of time order. If you specify a non-zero value, it must be greater than or equal to one second. NOTE: Latency is applicable only when you send data by using the post data API.
	/// </para>
	/// </summary>
	public AnalysisConfigDescriptor Latency(Elastic.Clients.Elasticsearch.Duration? latency)
	{
		LatencyValue = latency;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Advanced configuration option. Affects the pruning of models that have not been updated for the given time duration. The value must be set to a multiple of the <c>bucket_span</c>. If set too low, important information may be removed from the model. For jobs created in 8.1 and later, the default value is the greater of <c>30d</c> or 20 times <c>bucket_span</c>.
	/// </para>
	/// </summary>
	public AnalysisConfigDescriptor ModelPruneWindow(Elastic.Clients.Elasticsearch.Duration? modelPruneWindow)
	{
		ModelPruneWindowValue = modelPruneWindow;
		return Self;
	}

	/// <summary>
	/// <para>
	/// This functionality is reserved for internal use. It is not supported for use in customer environments and is not subject to the support SLA of official GA features. If set to <c>true</c>, the analysis will automatically find correlations between metrics for a given by field value and report anomalies when those correlations cease to hold. For example, suppose CPU and memory usage on host A is usually highly correlated with the same metrics on host B. Perhaps this correlation occurs because they are running a load-balanced application. If you enable this property, anomalies will be reported when, for example, CPU usage on host A is high and the value of CPU usage on host B is low. That is to say, you’ll see an anomaly when the CPU of host A is unusual given the CPU of host B. To use the <c>multivariate_by_fields</c> property, you must also specify <c>by_field_name</c> in your detector.
	/// </para>
	/// </summary>
	public AnalysisConfigDescriptor MultivariateByFields(bool? multivariateByFields = true)
	{
		MultivariateByFieldsValue = multivariateByFields;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Settings related to how categorization interacts with partition fields.
	/// </para>
	/// </summary>
	public AnalysisConfigDescriptor PerPartitionCategorization(Elastic.Clients.Elasticsearch.MachineLearning.PerPartitionCategorization? perPartitionCategorization)
	{
		PerPartitionCategorizationDescriptor = null;
		PerPartitionCategorizationDescriptorAction = null;
		PerPartitionCategorizationValue = perPartitionCategorization;
		return Self;
	}

	public AnalysisConfigDescriptor PerPartitionCategorization(Elastic.Clients.Elasticsearch.MachineLearning.PerPartitionCategorizationDescriptor descriptor)
	{
		PerPartitionCategorizationValue = null;
		PerPartitionCategorizationDescriptorAction = null;
		PerPartitionCategorizationDescriptor = descriptor;
		return Self;
	}

	public AnalysisConfigDescriptor PerPartitionCategorization(Action<Elastic.Clients.Elasticsearch.MachineLearning.PerPartitionCategorizationDescriptor> configure)
	{
		PerPartitionCategorizationValue = null;
		PerPartitionCategorizationDescriptor = null;
		PerPartitionCategorizationDescriptorAction = configure;
		return Self;
	}

	/// <summary>
	/// <para>
	/// If this property is specified, the data that is fed to the job is expected to be pre-summarized. This property value is the name of the field that contains the count of raw data points that have been summarized. The same <c>summary_count_field_name</c> applies to all detectors in the job. NOTE: The <c>summary_count_field_name</c> property cannot be used with the <c>metric</c> function.
	/// </para>
	/// </summary>
	public AnalysisConfigDescriptor SummaryCountFieldName(Elastic.Clients.Elasticsearch.Field? summaryCountFieldName)
	{
		SummaryCountFieldNameValue = summaryCountFieldName;
		return Self;
	}

	/// <summary>
	/// <para>
	/// If this property is specified, the data that is fed to the job is expected to be pre-summarized. This property value is the name of the field that contains the count of raw data points that have been summarized. The same <c>summary_count_field_name</c> applies to all detectors in the job. NOTE: The <c>summary_count_field_name</c> property cannot be used with the <c>metric</c> function.
	/// </para>
	/// </summary>
	public AnalysisConfigDescriptor SummaryCountFieldName<TDocument, TValue>(Expression<Func<TDocument, TValue>> summaryCountFieldName)
	{
		SummaryCountFieldNameValue = summaryCountFieldName;
		return Self;
	}

	/// <summary>
	/// <para>
	/// If this property is specified, the data that is fed to the job is expected to be pre-summarized. This property value is the name of the field that contains the count of raw data points that have been summarized. The same <c>summary_count_field_name</c> applies to all detectors in the job. NOTE: The <c>summary_count_field_name</c> property cannot be used with the <c>metric</c> function.
	/// </para>
	/// </summary>
	public AnalysisConfigDescriptor SummaryCountFieldName<TDocument>(Expression<Func<TDocument, object>> summaryCountFieldName)
	{
		SummaryCountFieldNameValue = summaryCountFieldName;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (BucketSpanValue is not null)
		{
			writer.WritePropertyName("bucket_span");
			JsonSerializer.Serialize(writer, BucketSpanValue, options);
		}

		if (CategorizationAnalyzerValue is not null)
		{
			writer.WritePropertyName("categorization_analyzer");
			JsonSerializer.Serialize(writer, CategorizationAnalyzerValue, options);
		}

		if (CategorizationFieldNameValue is not null)
		{
			writer.WritePropertyName("categorization_field_name");
			JsonSerializer.Serialize(writer, CategorizationFieldNameValue, options);
		}

		if (CategorizationFiltersValue is not null)
		{
			writer.WritePropertyName("categorization_filters");
			JsonSerializer.Serialize(writer, CategorizationFiltersValue, options);
		}

		if (DetectorsDescriptor is not null)
		{
			writer.WritePropertyName("detectors");
			writer.WriteStartArray();
			JsonSerializer.Serialize(writer, DetectorsDescriptor, options);
			writer.WriteEndArray();
		}
		else if (DetectorsDescriptorAction is not null)
		{
			writer.WritePropertyName("detectors");
			writer.WriteStartArray();
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.MachineLearning.DetectorDescriptor(DetectorsDescriptorAction), options);
			writer.WriteEndArray();
		}
		else if (DetectorsDescriptorActions is not null)
		{
			writer.WritePropertyName("detectors");
			writer.WriteStartArray();
			foreach (var action in DetectorsDescriptorActions)
			{
				JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.MachineLearning.DetectorDescriptor(action), options);
			}

			writer.WriteEndArray();
		}
		else
		{
			writer.WritePropertyName("detectors");
			JsonSerializer.Serialize(writer, DetectorsValue, options);
		}

		if (InfluencersValue is not null)
		{
			writer.WritePropertyName("influencers");
			JsonSerializer.Serialize(writer, InfluencersValue, options);
		}

		if (LatencyValue is not null)
		{
			writer.WritePropertyName("latency");
			JsonSerializer.Serialize(writer, LatencyValue, options);
		}

		if (ModelPruneWindowValue is not null)
		{
			writer.WritePropertyName("model_prune_window");
			JsonSerializer.Serialize(writer, ModelPruneWindowValue, options);
		}

		if (MultivariateByFieldsValue.HasValue)
		{
			writer.WritePropertyName("multivariate_by_fields");
			writer.WriteBooleanValue(MultivariateByFieldsValue.Value);
		}

		if (PerPartitionCategorizationDescriptor is not null)
		{
			writer.WritePropertyName("per_partition_categorization");
			JsonSerializer.Serialize(writer, PerPartitionCategorizationDescriptor, options);
		}
		else if (PerPartitionCategorizationDescriptorAction is not null)
		{
			writer.WritePropertyName("per_partition_categorization");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.MachineLearning.PerPartitionCategorizationDescriptor(PerPartitionCategorizationDescriptorAction), options);
		}
		else if (PerPartitionCategorizationValue is not null)
		{
			writer.WritePropertyName("per_partition_categorization");
			JsonSerializer.Serialize(writer, PerPartitionCategorizationValue, options);
		}

		if (SummaryCountFieldNameValue is not null)
		{
			writer.WritePropertyName("summary_count_field_name");
			JsonSerializer.Serialize(writer, SummaryCountFieldNameValue, options);
		}

		writer.WriteEndObject();
	}
}